import {Component, Input,} from '@angular/core';

import {Cart} from "../../../models/Cart";


import {CategoryProvider} from "../../../providers/category";
import {NavController} from "ionic-angular";
import {EmployeeHomePage} from "../../pages/home/home";
import {EmployeeShoppingCartPage} from "../../pages/shopping-cart/shopping-cart";
import {AlertPage} from "../../pages/alert/alert";
import {CartProvider} from "../../../providers/cartProvider";
import {MenuPage} from "../../../customer/pages/menu/menu";

/**
 * Generated class for the CustomerHeaderComponent component.
 *
 * See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html
 * for more info on Angular Components.
 */
@Component({
  selector: 'employee-header',
  templateUrl: 'employee-header.html'
})
export class EmployeeHeaderComponent {

  @Input() showCate: boolean;
  categories: Cart[];
  store: any;
  Table_ID = '11A';
  keywords: string;
  show = true;

  constructor(public cateProd: CategoryProvider,
              public cartPro: CartProvider,
              public nav: NavController,) {
    this.keywords = localStorage.getItem('keywords');
    this.cateProd.getCategories().subscribe(categories => {
      this.categories = categories
    });
    this.cartPro.getTables().subscribe(Stores => {
      this.store = Stores;
      console.log(this.store)
    });
    if (this.cartPro.Table_ID() != null) {
      this.show=false;
      this.Table_ID = this.cartPro.Table_ID();
      console.log(this.Table_ID);
    }
  }

  search(ev) {
    // set val to the value of the ev target
    let val = ev.target.value;
    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      console.log('header', val);
      localStorage.setItem("keywords", val);
      setTimeout(300);
      this.nav.setRoot(EmployeeHomePage, {keywords: val});
    }

  }

  showCart() {
    this.nav.push(EmployeeShoppingCartPage);
  }

  openModel() {
    this.nav.push(AlertPage);
  }

  showList(name: string) {
    this.nav.setRoot(EmployeeHomePage, {category: name});
  }

  showAll() {
    this.nav.push(MenuPage);
  }
}
